//
//  UIWebView+JS.m
//  duzhoumo
//
//  Created by 度周末网络-王腾 on 15/11/11.
//  Copyright © 2015年 dzmmac. All rights reserved.
//

#import "UIWebView+JS.h"
#import "NSUserDefaults+Addition.h"
#import "ApiConfig.h"
@implementation UIWebView (JS)

/**
 *  获取js 上下文环境 需要导入 coreJavascript
 *
 *  @return JSContext
 */
-(id)getJSContext{
   return  [self valueForKeyPath:@"documentView.webView.mainFrame.javaScriptContext"];
}



/**
 *  获取HTML字符串
 *
 *  @return HTML字符串
 */
-(NSString *)getHtmlString{
   return  [self stringByEvaluatingJavaScriptFromString:@"document.getElementsByTagName('html')[0].outerHTML"];
}

/**
 *  禁止选中和长按
 */
-(void)enableSelectedAndTouchCallout{
    [self stringByEvaluatingJavaScriptFromString:@"document.documentElement.style.webkitUserSelect='none';"];
    [self stringByEvaluatingJavaScriptFromString:@"document.documentElement.style.webkitTouchCallout='none';"];
}

/**
 *  添加图片预览
 */
-(void)addImgPerviewJS{
    [self stringByEvaluatingJavaScriptFromString:@"function assignImageClickAction(){var imgs=document.getElementsByTagName('img');var length=imgs.length;for(var i=0;i<length;i++){img=imgs[i];img.onclick=function(){window.location.href='image-preview:'+this.src}}}"];
    [self stringByEvaluatingJavaScriptFromString:@"assignImageClickAction();"];
}


@end
